package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 维护错误码之后也要维护错误描述
 */
public enum ServiceGoodsExceptionEnum implements IntegerEnum<Integer> {
    SERVICE_CATEGORY_NAME_REPEAT(120001, "服务商品分类名称重复"),
    SERVICE_CATEGORY_NOT_EXISTS(120002, "服务商品分类不存在"),


    SERVICE_GROUP_NAME_REPEAT(140011, "服务商品分组名称重复"),
    SERVICE_GROUP_PARENT_NOT_EXISTS(140012, "服务商品分组上级不存在"),

    SERVICE_GROUP_SECOND_SAFE(140013, "服务商品分组只能添加两级"),
    SERVICE_GROUP_SHOP_SAFE(140014, "只能操作自己店铺的服务商品分组"),
    SERVICE_GROUP_SELECT_SELF(140015, "服务商品分组上级不能是自己"),
    SERVICE_GROUP_REMOVE_SAFE(140016, "当前服务商品分组下有子分组不能删除"),
    SERVICE_GROUP_NOT_EXISTS(140017, "服务商品分组不存在"),

    SERVICE_GOODS_NOT_EXISTS(140031, "服务商品不存在"),
    ;


    private Integer code;
    private String msg;

    ServiceGoodsExceptionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @JsonCreator
    public static ServiceGoodsExceptionEnum getByCode(int code) {
        for (ServiceGoodsExceptionEnum value : ServiceGoodsExceptionEnum.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
